/**
 * @file:air_conditioning.c
 * @brief:空调状态机
 * @author:liaowx
 * @date:2019.08.02
 */
#include <stdio.h>
#include <string.h>

#include "air_conditioning.h"

void run(struct air_conditioning *cur_state, int ret, 
            struct air_conditioning *dst_state)
{
    if (!strcmp(cur_state->name, "OFF")) {
        switch (ret) {
            case OPEN :
                cur_state->name = dst_state->name;
                cur_state->temperature = dst_state->temperature;
                cur_state->wind_speed = dst_state->wind_speed;
                printf("打开空调\n");
                break;
        }
    }
    if (!strcmp(cur_state->name, "ON")) {
        switch (ret) {
            case CLOSE :
                cur_state->name = dst_state->name;
                cur_state->temperature = dst_state->temperature;
                cur_state->wind_speed = dst_state->wind_speed;
                printf("关闭空调\n");
                break;

            case MAKE_COLD :
                cur_state->name = dst_state->name;
                cur_state->temperature = dst_state->temperature;
                cur_state->wind_speed = dst_state->wind_speed;
                printf("开始制冷\n");
                break;
        }
    }
    if (!strcmp(cur_state->name, "REFRIGERATION")) {
        switch (ret) {
            case CLOSE :
                cur_state->name = dst_state->name;
                cur_state->temperature = dst_state->temperature;
                cur_state->wind_speed = dst_state->wind_speed;
                printf("关闭空调\n");
                break;
        }
    }
}

void state_init(struct air_conditioning *state,
                char *name, int temperature, int wind_speed)
{
    state->name = name;
    state->temperature = temperature;
    state->wind_speed = wind_speed;
}